﻿using jq9602_jq9603.ViewModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace jq9602_jq9603.View
{
    /// <summary>
    /// MainView.xaml 的交互逻辑
    /// </summary>
    public partial class MainView : Window
    {
        public MainView()
        {
            InitializeComponent();
            if (DataContext is MainViewModel vm)
            {
                vm.CloseRequested += (s, e) => Close(); // 响应关闭请求
            }
        }

        private void Border_MouseLeftButtonDoubleDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ClickCount == 2)
            {
                WindowState = WindowState == WindowState.Normal ? WindowState.Maximized : WindowState.Normal;
            }
        }

        private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
                this.DragMove();
        }

        private void btnToggleWin_Click(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState == WindowState.Normal ? WindowState.Maximized : WindowState.Normal;
        }

        private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var dg = sender as DataGrid;
            if (dg?.SelectedItem != null)
            {
                dg.ScrollIntoView((dg.SelectedItem));
            }
        }
    }
}